package com.youyiwen.Service.impl;

import com.youyiwen.Bean.ChatList;
import com.youyiwen.Bean.User;
import com.youyiwen.Mapper.ChatListMapper;
import com.youyiwen.Mapper.UserMapper;
import com.youyiwen.Service.ChatListService;
import com.youyiwen.dto.ChatListDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zhaoyang
 * @Date: 2021/04/18
 */
@Service
public class ChatListServiceImpl implements ChatListService {

    @Autowired
    private ChatListMapper chatListMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<ChatListDTO> list(String me) {
        List<ChatListDTO> list = new ArrayList<>();
        List<ChatList> chatLists = chatListMapper.chatList(me);
        for (ChatList chatList : chatLists) {
            ChatListDTO chatListDTO = new ChatListDTO();
            chatListDTO.setChatList(chatList);
            String othersName = chatList.getOthers();
            User others = userMapper.selectUserByName(othersName);
            chatListDTO.setOthers(others);
            list.add(chatListDTO);
        }
        return list;
    }
}
